﻿using System.Runtime.InteropServices;

namespace BM.Core
{
    /// <summary>
    /// This class will do something relate with system
    /// </summary>
    public static class NativeMethods
    {
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public class MemoryStatusEX
        {
            public uint dwLength;
            public uint dwMemoryLoad;
            public ulong ullTotalPhys;
            public ulong ullAvailPhys;
            public ulong ullTotalPageFile;
            public ulong ullAvailPageFile;
            public ulong ullTotalVirtual;
            public ulong ullAvailVirtual;
            public ulong ullAvailExtendedVirtual;

            public MemoryStatusEX()
            {
                dwLength = (uint) Marshal.SizeOf(typeof(NativeMethods.MemoryStatusEX));
            }
        }

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern bool GlobalMemoryStatusEx([In, Out] MemoryStatusEX lpBuffer);

        /// <summary>
        /// Retrive total RAM memory on your computer
        /// </summary>
        /// <param name="lpBuffer">MEMORYSTATUSEX</param>
        /// <returns>Bool value indicates this function run correctly or not</returns>
        public static bool GLobalMemoryStatusExManaged(MemoryStatusEX lpBuffer)
        {
            return GlobalMemoryStatusEx(lpBuffer);
        }
    }
}
